<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>业务处理-供货协议-供货协议</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
	<style type="text/css">
	 .form label { display: inline-block; text-align: right; width:85px;}
	</style>
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>供货协议</a></div>
			<div class="search">
			<form action="<%=basePath %>supplyagreement/paginglist.do" method="post" class="form">
				<input type="hidden" name="currentPage" value="1">
				<p>
						<label>协议代码</label>
						<input type="text" name="protocolcode" value="${supplyAgreementPage.protocolcode }" class="form-control"></input>
						<label >邮轮</label>
						<select name="companyid" class="form-control select">
							<option></option>
						</select>
						<label>说明</label>
						<input type="text"  name="protocolexplain" value="${supplyAgreementPage.protocolexplain }" class="form-control"></input>
				</p>
				<p>
						<label>供应商代码</label>
						<input type="text" name="suppliercode" value="${supplyAgreementPage.suppliercode }" class="form-control"></input>
						<label>状态</label>
						<select name="protocostatus" class="form-control select">
							<option value="">全部</option>
							<option value="可用">可用</option>
							<option value="不可用">不可用</option>
						</select>
						<label>供应商名称</label>
						<input type="text"  name="suppliername" value="${supplyAgreementPage.suppliername }" class="form-control"></input>
				</p>
				<p>
						<label>协议开始时间</label>
						<input type="text" name="starttime1" value="${supplyAgreementPage.starttime1 }" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
						<label>至</label>
						<input type="text" name="starttime2" value="${supplyAgreementPage.starttime2 }" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
						<label>协议结束时间</label>
						<input type="text" name="endtime1" value="${supplyAgreementPage.endtime1 }" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
						<label>至</label>
						<input type="text" name="endtime2" value="${supplyAgreementPage.endtime2 }" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
						<input type="submit" value="查询"  class="btn btn1"></input>
						<input type="button" value="清空" onclick="clearSearchParam();" class="btn btn1"></input>
				</p>
			</form>
			</div>
			<div class="btn rightBtn">
				<c:if test="${isAdd }">
					<input type="button" value="新增" onclick="addSupplyAgreement();" class="btn btn1"></input>
				</c:if>
				<input type="button" value="编辑" onclick="toEditSupplyAgreement();" class="btn btn1"></input>
				<c:if test="${isDelete }">
					<input type="button" value="删除"  onclick="toDeleteSupplyAgreement();" class="btn btn1"></input>
				</c:if>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:200px;">操作</th>
							<th>协议代码</th>
							<th>协议说明</th>
							<th>供应商代码</th>
							<th>供应商名称</th>
							<th>状态</th>
							<th>生效时间</th>
							<th>创建人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${agreementList}" var="supplyagreement" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateSupplyAgreement" value="${supplyagreement.supplyagreementid }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn1" onclick="editSupplyAgreement(${supplyagreement.supplyagreementid });">编辑</a>
									<a class="btn btn-xs btn1" onclick="downloadAgreementAnnex(${supplyagreement.supplyagreementid });">附件</a>
									<c:if test="${isDelete }">
										<a class="btn btn-xs btn_danger" onclick="confirmDeleteSupplyAgreement(${supplyagreement.supplyagreementid });">删除</a>
									</c:if>
								</td>
								<td>${supplyagreement.protocolcode }</td>
								<td>${supplyagreement.protocolexplain }</td>
								<td>${supplyagreement.suppliercode }</td>
								<td>${supplyagreement.suppliername }</td>
								<td>${supplyagreement.protocostatus }</td>
								<td><fmt:formatDate value="${supplyagreement.starttime }"
										type="date" />- <fmt:formatDate
										value="${supplyagreement.endtime }" type="date" /></td>
								<td>${supplyagreement.createpersonname }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/supplyAgreement/addSupplyAgreement.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	
	function clearSearchParam(){
		$(".search input:text").val("");
		$(".search select").val("");
	}
	
	function selectRow(obj){
		$(obj).find('input:radio[name="operateSupplyAgreement"]')[0].checked=true;
	}
	
	function toEditSupplyAgreement(){
		var radio=$('input:radio[name="operateSupplyAgreement"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的供货协议！");
			return;
		}
		editSupplyAgreement(radio.val());
	}
	
	function editSupplyAgreement(supplyagreementid){
		location.href="<%=basePath %>supplyagreement/toUpdate.do?supplyagreementid="+supplyagreementid;
	}
	
	function downloadAgreementAnnex(supplyagreementid){
		window.open("<%=basePath %>supplyagreement/fileDownload.do?supplyagreementid="+supplyagreementid);
	}
	
	function toDeleteSupplyAgreement(){
		var radio=$('input:radio[name="operateSupplyAgreement"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的供货协议！");
			return;
		}
		confirmDeleteSupplyAgreement(radio.val());
	}
		
	function confirmDeleteSupplyAgreement(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>supplyagreement/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "supplyagreementid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","供货协议已删除！",Prompt.refresh);
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该供货协议吗?删除后无法恢复",delFunc);
	}
	</script>
</body>
</html>